<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet"/>
    <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
    <link th:href="@{/erp/assets/css/codemirror.css}" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}"/>
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome.min.css}"/>
    <script th:src="@{/erp/assets/js/jquery.min.js}"></script>
    <script th:src="@{/erp/assets/js/bootstrap.min.js}"></script>
    <!-- page specific plugin scripts -->
    <script th:src="@{/erp/assets/js/jquery.dataTables.min.js}"></script>
    <script th:src="@{/erp/assets/js/jquery.dataTables.bootstrap.js}"></script>
    <script th:src="@{/erp/assets/layer/layer.js}" type="text/javascript"></script>
    <title>货位添加</title>
</head>
<body>
<form>
    <!--销售区域分配图层-->
    <div class="add_menber" id="add_menber_style">
        <ul class=" page-content">
            <div class="Operate_cont clearfix">
                <label class="form-label"><span class="c-red">*</span>所属货区：</label>
                <div class="formControls " style="width:280px;">
                    <!--下拉框-->
                    <select name="warehouseId" required onchange="getAreaByWid()" id="warehouseName" style="margin-left:10px;">
                        <option value="" selected disabled>--请选择仓库--</option>
                    </select>
                    <select name="areaId" required id="areaName" onchange="getShelfByAid()" style="margin-left:10px;">
                        <option value="" selected disabled>--请选择货区--</option>
                    </select>
                </div>
            </div>
            <div class="Operate_cont clearfix">
                <label class="form-label"><span class="c-red">*</span>货架编号：</label>
                <div class="formControls ">
                    <select name="shelfId" required id="shelfNo" style="margin-left:10px;">
                        <option value="" selected disabled>--请选择货架--</option>
                    </select>
                </div>
            </div>
            <div class="Operate_cont clearfix">
                <label class="form-label"><span class="c-red">*</span>货位编号：</label>
                <div class="formControls ">
                    <input type="text" required class="input-text" value="" placeholder="" name="cargoSpaceNo">
                </div>
            </div>
            <!--   <div class="Operate_cont clearfix">
                   <label class="form-label"><span class="c-red">*</span>负责人：</label>
                   <div class="formControls ">
                       <input type="text" class="input-text" value="" placeholder="" name="负责人">
                   </div>
               </div>
               <div class="Operate_cont clearfix">
                   <label class="form-label"><span class="c-red">*</span>联系电话：</label>
                   <div class="formControls ">
                       <input type="text" class="input-text" value="" placeholder="" id="user-name" name="联系电话">
                   </div>
               </div>-->
            <div class="Operate_cont clearfix">
                <label class="form-label"><span class="c-red">*</span>描述：</label>
                <div class="formControls "><textarea required name="cargoSpaceRemark"></textarea>
                </div>
            </div>

            <div class="" style=" text-align:center">
                <input class="btn btn-primary" id="tijiao" type="submit" value="提交">
                <input class="btn btn-primary" id="tijiao1" type="reset" value="取消">
            </div>
        </ul>
    </div>
</form>

<script>
    jQuery(function ($) {
        $.ajax({
            url: '/warehouse/list',
            type: 'post',
            success: function (res) {
                for (var i = 0; i < res.length; i++) {
                    $("#warehouseName").append('<option value="' + res[i].id + '">' + res[i].warehouseName + '</option>')
                }
            }
        });

        $('form').submit(function () {
            var data = $('form').serialize();
            $.ajax({
                url: '/cargoSpace/add',
                type: 'post',
                data: data,
                success: function (res) {
                    if (res.rs) {
                        parent.layer.msg(res.msg, {icon: 1});
                        $('#btn',parent.window.document).click();
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }
            })
            return false;
        });

        $('#tijiao1').on('click', function () {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });
    });

    //仓库联动库区
    function getAreaByWid() {
        var wId = $("#warehouseName").find("option:selected").val();
        $("#areaName").empty();
        $.post("/area/listByWid", {warehouseId: wId}, function (res) {
            $("#areaName").append('<option value="" selected disabled>--请选择货区--</option>');
            for (var i = 0; i < res.length; i++) {
                $("#areaName").append('<option value="' + res[i].id + '">' + res[i].areaName + '</option>')
            }
        });
        return false;
    }

    //货区联动货架
    function getShelfByAid() {
        var aid = $("#areaName").find("option:selected").val();
        $("#shelfNo").empty();
        $.post("/shelf/listByAid", {areaId: aid}, function (res) {
            $("#shelfNo").append('<option value="" selected disabled>--请选择货架--</option>');
            for (var i = 0; i < res.length; i++) {
                $("#shelfNo").append('<option value="' + res[i].id + '">' + res[i].shelfNo + '</option>')
            }
        });
        return false;
    }

</script>


</body>
</html>


